package com.springboot.bookmanegersystem.model.resp;

import lombok.Data;
import lombok.Getter;

/**
 * Created with IntelliJ IDEA.
 * Description :
 * User: jiume
 * Date: 2025-05-08
 * Time: 19:55
 */
// 统一结果返回
@Data
public class Result<T> {
    private ResultCodeEnum resultCodeEnum;
    private String message;
    private T data;

    // 操作成功
    public static <T> Result<T> success() {
        Result<T> result = new Result<>();
        result.resultCodeEnum = ResultCodeEnum.SUCCESS;
        result.message = "";
        result.data = null;
        return result;
    }

    // 操作成功
    public static <T> Result<T> success(T data) {
        Result<T> result = success();
        result.data = data;
        return result;
    }

    // 操作失败
    public static <T> Result<T> error(String message) {
        Result<T> result = new Result<>();
        result.resultCodeEnum = ResultCodeEnum.ERROR;
        result.message = message;
        result.data = null;
        return result;
    }

    // 服务异常
    public static <T> Result<T> fatal() {
        Result<T> result = new Result<>();
        result.resultCodeEnum = ResultCodeEnum.FATAL;
        result.message = "";
        result.data = null;
        return result;
    }

    // 服务异常
    public static <T> Result<T> fatal(String message) {
        Result<T> result = new Result<>();
        result.resultCodeEnum = ResultCodeEnum.FATAL;
        result.message = message;
        result.data = null;
        return result;
    }
}
